﻿using System;
using System.Collections;
using System.Collections.Generic;
using Table.Blo;
using UnityEngine;
using UnityEngine.UI;

public class SandItem : MonoBehaviour
{
    public Text mapName;
    public TextureKit mapIconKit;
    public UGUIToggle toggle;

    private ChessSandShopPage.ChessMapInfo mapInfo;
    private Action<ChessSandShopPage.ChessMapInfo> onClickCall;
    public void InitSand(ChessSandShopPage.ChessMapInfo chessMapInfo,Action<ChessSandShopPage.ChessMapInfo> onClick)
    {
        mapName.text = chessMapInfo.mapName;
        mapIconKit.TextureName = chessMapInfo.mapData.mapIcon;
        mapInfo = chessMapInfo;

        onClickCall = onClick;
        toggle.onValueChangedEvent = OnValueChangedEvent;    
    }

    public bool IsUsed()
    {
        return mapInfo.isUsed;
    }

    public void SelectedToggle()
    {
        toggle.isOn = true;
    }

    private void OnValueChangedEvent(object obj,bool value)
    {
        if (value)
        {
            onClickCall(mapInfo);
        }
    }
}
